package de.velvettear.squirrel.util;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Handler;
import de.velvettear.squirrel.kernel.Statics;

public class DialogHelper {

	public static AlertDialog createConfirmationDialog(Context context, String title, String message, String okButton, String cancelButton, Handler dialogHandler) {
		return createConfirmationDialog(context, title, message, okButton, cancelButton, dialogHandler, null);
	}
	
	public static AlertDialog createConfirmationDialog(Context context, String title, String message, String okButton, String cancelButton, Handler dialogHandler, String command) {
		final Handler handler = dialogHandler;		
		final String messageCommand = command;
		
		AlertDialog dialog = new AlertDialog.Builder(context).create();
		dialog.setTitle(title);
		dialog.setMessage(message);		
		dialog.setButton(Dialog.BUTTON_NEGATIVE, cancelButton, new DialogInterface.OnClickListener() {			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				handler.sendMessage(MessageHelper.createMessage(Statics.HANDLER_DIALOG, Statics.COMMAND_DIALOG_CANCEL, null));
			}
		});
		
		dialog.setButton(Dialog.BUTTON_POSITIVE, okButton, new DialogInterface.OnClickListener() {			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				if (messageCommand != null) {
					handler.sendMessage(MessageHelper.createMessage(Statics.HANDLER_DIALOG, Statics.COMMAND_DIALOG_OK, messageCommand));	
				} else {
					handler.sendMessage(MessageHelper.createMessage(Statics.HANDLER_DIALOG, Statics.COMMAND_DIALOG_OK, null));	
				}				
			}
		});
		
		return dialog;
	}
	
}
